﻿<!--
Project: ClipFlair (http://ClipFlair.codeplex.com)
Filename: PivotViewerExt/Themes/Generic.xaml
Version: 20150203
-->

<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:sdk="clr-namespace:System.Windows.Controls.Pivot;assembly=System.Windows.Controls.Pivot"
  xmlns:con="clr-namespace:Microsoft.Internal.Pivot.Controls;assembly=System.Windows.Controls.Pivot"  
  xmlns:utils="clr-namespace:Utils.Converters;assembly=Utils"
  mc:Ignorable="d"
  >  
  
  <!-- using sdk instead of pivot prefix to avoid doing changes to style copied from PivotViewer (downloaded from http://visuallylocated.com/post/2012/01/23/Basic-styling-of-the-Silverlight-5-PivotViewer.aspx) -->

  <utils:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />

  <!-- -->

  <Thickness x:Key="FocusedBorderThickness">1</Thickness>
  <Thickness x:Key="UnfocusedBorderThickness">0</Thickness>

  <!-- -->

  <Style x:Key="DefaultItemAdornerStyle" TargetType="sdk:PivotViewerDefaultItemAdorner">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="sdk:PivotViewerDefaultItemAdorner">

          <Grid x:Name="PART_Root" Background="Transparent">
            <Grid.Resources>
              <Style x:Name="CommandButtonStyle" TargetType="Button">
                <Style.Setters>
                  <Setter Property="Background" Value="Transparent"/>
                  <Setter Property="Template">
                    <Setter.Value>
                      <ControlTemplate TargetType="Button">
                        <Grid Background="Transparent">
                          <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                              <VisualState x:Name="Normal"/>
                              <VisualState x:Name="MouseOver">
                                <Storyboard>
                                  <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HoverBorder">
                                    <EasingDoubleKeyFrame KeyTime="0" Value="0.3"/>
                                  </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                              </VisualState>
                              <VisualState x:Name="Disabled"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                              <VisualState x:Name="Focused">
                                <Storyboard>
                                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="FocusBorder">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                                  </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                              </VisualState>
                              <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                          </VisualStateManager.VisualStateGroups>
                          <Border x:Name="HoverBorder" Background="{Binding (con:FrameworkElementExtensions.Brushes)[FilterBorderBrush], RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sdk:PivotViewer}}"
                                                                                 BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sdk:PivotViewer}}" BorderThickness="1" Opacity="0.1" Margin="-1"/>
                          <Border x:Name="FocusBorder" Margin="-1" Visibility="Collapsed" BorderThickness="{StaticResource FocusedBorderThickness}" BorderBrush="{Binding (con:FrameworkElementExtensions.Brushes)[FocusBorderBrush], RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sdk:PivotViewer}}"/>
                          <ContentPresenter Margin="3"/>
                        </Grid>
                      </ControlTemplate>
                    </Setter.Value>
                  </Setter>
                </Style.Setters>
              </Style>

              <Storyboard x:Key="SmallGroupStoryBoard">
                <!-- x:Key="OpacityAnimation"-->
                <DoubleAnimationUsingKeyFrames
                                    Storyboard.TargetProperty="Opacity"
                                    Duration="0:0:0.8">
                  <SplineDoubleKeyFrame KeyTime="0:0:0.8"
                                        KeySpline="0,0.03,0.32,1" />
                </DoubleAnimationUsingKeyFrames>

                <!-- x:Key="WidthAnimation" -->
                <DoubleAnimationUsingKeyFrames
                                    Storyboard.TargetProperty="Width"
                                    Duration="0:0:0.8">
                  <SplineDoubleKeyFrame KeyTime="0:0:0.8"
                                        KeySpline="0,0.03,0.32,1" />
                </DoubleAnimationUsingKeyFrames>
              </Storyboard>

              <Storyboard x:Key="LargeGroupStoryBoard">
                <!-- x:Key="OpacityAnimation" -->
                <DoubleAnimationUsingKeyFrames
                                    Storyboard.TargetProperty="Opacity"
                                    Duration="0:0:0.8">
                  <SplineDoubleKeyFrame KeyTime="0:0:0.8"
                                        KeySpline="0,0.03,0.32,1" />
                </DoubleAnimationUsingKeyFrames>

                <!-- x:Key="WidthAnimation" -->
                <DoubleAnimationUsingKeyFrames
                  Storyboard.TargetProperty="Width"
                  Duration="0:0:0.8"
                  >
                  <SplineDoubleKeyFrame
                    KeyTime="0:0:0.8"
                    KeySpline="0,0.03,0.32,1"
                    />
                </DoubleAnimationUsingKeyFrames>

                <!--  x:Key="HeightAnimation" -->
                <DoubleAnimationUsingKeyFrames
                  Storyboard.TargetProperty="Height"
                  Duration="0:0:0.8"
                  >
                  <SplineDoubleKeyFrame
                    KeyTime="0:0:0.8"
                    KeySpline="0,0.03,0.32,1"
                    />
                </DoubleAnimationUsingKeyFrames>
              </Storyboard>

            </Grid.Resources>

            <VisualStateManager.VisualStateGroups>

              <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal"/>

                <VisualState x:Name="MouseOver">
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames
                      Storyboard.TargetProperty="(UIElement.Opacity)"
                      Storyboard.TargetName="ButtonBorder"
                      >
                      <EasingDoubleKeyFrame
                        KeyTime="0"
                        Value="1"
                        />
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>

                <VisualState x:Name="Disabled"/>
              </VisualStateGroup>

              <VisualStateGroup x:Name="ItemStates">
                <VisualState x:Name="Default"/>

                <VisualState x:Name="IsSelected">
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames
                      Storyboard.TargetProperty="(UIElement.Opacity)"
                      Storyboard.TargetName="FocusedItemBorder"
                      >
                      <EasingDoubleKeyFrame
                        KeyTime="0"
                        Value="1"
                        />
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>

              </VisualStateGroup>

            </VisualStateManager.VisualStateGroups>

            <Border
              x:Name="ButtonBorder"
              Margin="-1"
              BorderThickness="4"
              BorderBrush="{Binding (con:FrameworkElementExtensions.Brushes)[ControlHoverBackground], RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sdk:PivotViewer}}"
              Opacity="1"
              />

            <Border
              x:Name="FocusedItemBorder"
              Margin="-1"
              BorderThickness="4"
              BorderBrush="{Binding (con:FrameworkElementExtensions.Brushes)[FocusBorderBrush], RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sdk:PivotViewer}}"
              Opacity="0"
              />

            <con:ShrinkBasedMultiSizeControl x:Name="PART_CommandContainer" MinDisplayableWidth="80" Margin="-1" UseLayoutRounding="False">
                <Border
                  x:Name="CommandItem"
                  con:ShrinkBasedMultiSizeControl.ShrinkStoryboard="{StaticResource LargeGroupStoryBoard}"
                  Background="Transparent"
                  HorizontalAlignment="Right"
                  VerticalAlignment="Top"
                  >
                  <ItemsControl
                    IsTabStop="False"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top"
                    ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Commands}"
                    >

                    <ItemsControl.ItemTemplate>
                      <DataTemplate>
                        <Button
                          x:Name="CommandButton"
                          Style="{StaticResource CommandButtonStyle}"
                          Command="{Binding}"
                          CommandParameter="{Binding DataContext, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=con:ShrinkBasedMultiSizeControl}}"
                          ToolTipService.ToolTip="{Binding ToolTip}"
                          >
                          <Grid>
                            <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <Border
                              x:Name="Unshrinkable"
                              con:ShrinkBasedMultiSizeControl.ShrinkGroup="Never" 
                              Grid.Column="0"
                              Visibility="{Binding Icon, Converter={StaticResource NullToVisibilityConverter}}"
                              >
                              <Image
                                x:Name="unshrinkableElement"
                                Source="{Binding Icon}" Margin="2,0,2,0"
                                />
                                <!-- Width="16" Height="16" -->
                            </Border>

                            <Border
                              x:Name="Shrinkable"
                              con:ShrinkBasedMultiSizeControl.ShrinkGroup="Small"
                              con:ShrinkBasedMultiSizeControl.ShrinkStoryboard="{StaticResource SmallGroupStoryBoard}"                                                                        
                              Visibility="{Binding DisplayName, Converter={StaticResource NullToVisibilityConverter}}"
                              Grid.Column="1"
                              >
                              <TextBlock
                                x:Name="shrinkableElement" 
                                Margin="2,0,2,0"
                                Height="16"
                                Text="{Binding DisplayName}"
                                Foreground="{Binding SecondaryBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sdk:PivotViewer}}"
                                />
                            </Border>
                          </Grid>
                        </Button>
                      </DataTemplate>
                    </ItemsControl.ItemTemplate>

                    <ItemsControl.ItemsPanel>
                      <ItemsPanelTemplate>
                        <StackPanel
                          Orientation="Horizontal"
                          Background="{Binding BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sdk:PivotViewer}}"
                          />
                      </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                  </ItemsControl>
                </Border>
              </con:ShrinkBasedMultiSizeControl>

          </Grid>

        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>
